package com.zlx.controller;

import com.alibaba.fastjson.JSONObject;
import com.zlx.constants.Constant;
import com.zlx.entities.User;
import com.zlx.service.UserService;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.Properties;
import java.util.UUID;

/**
 * @ClassName ToQqLoginServlet
 * @Description 去qq登录校验的页面，qq用户登录完成直接跳回调函数
 * @Author Edward
 * @Date 2020/10/1 20:21
 */
@WebServlet("/qq/*")
public class ToQqLoginServlet extends BaseServlet {
    protected void toQQLogin(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //读取配置文件
        Properties properties = new Properties();
        properties.load(this.getClass().getClassLoader().getResourceAsStream("config.properties"));
        //读取appId
        String appid = properties.getProperty("qq.AppID");
        //读取密钥
        String AppSecret = properties.getProperty("qq.AppKey");
        //读取回调地址
        String baseUrl = properties.getProperty("qq.redirect_uri");
        String url ="https://graph.qq.com/oauth2.0/authorize?response_type=code" +  //response_type必选属性：属性值为code
                "&client_id="+appid+
                "&redirect_uri="+baseUrl+
                "&state=test";
        response.sendRedirect(url);
    }
}
